package com.soft.base.spring.redis;

import com.soft.base.contract.Cache;
import com.soft.base.contract.CacheFacade;
/**
 * class
 *
 * @author user
 * @date 2020/06/05
 */
public class RedisCacheFacade implements CacheFacade {

    public RedisCacheFacade() {
        Cache.boot(this);
    }

    @Override
    public void forget(String key) {
        RedisUtil.delete(key);
    }

    @Override
    public boolean exists(String key) {
        return RedisUtil.exists(key);
    }

    @Override
    public <T> T getObject(String key, Class<T> cls) {
        return RedisUtil.getObject(key, cls);
    }

    @Override
    public <T> void setObject(String key, T data) {
        RedisUtil.setObject(key, data);
    }

    @Override
    public <T> void setObject(String key, T data, long expire) {
        RedisUtil.setObject(key, data, expire);
    }

    @Override
    public <T> T remember(String key, long seconds, final RememberCallback<T> callback) {
        return RedisUtil.remember(key, seconds, () -> callback.get());
    }
}
